package com.pojo;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x){this.val = x;this.next = null;}

    ListNode(){}

    public void add(int x){
        ListNode node = new ListNode(x);
        if(this.next == null){
            this.next = node;
        }else{
            this.next.add(x);
        }
    }

    public static int getLength(ListNode root){
        if (root == null)
            return 0;
        int count = 0;
        while(root != null){
            count++;
            root = root.next;
        }
        return count;
    }


}
